using UnityEngine;
using System.Collections;

/// <summary>
/// This script goes on all the enemys
/// </summary>
public class Enemy : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnCollisionEnter(Collision other)
	{
		string tag = other.gameObject.tag;
		// if colides with player, so player get hurt.
		if (tag == "Player")
		{
			other.gameObject.GetComponent<Player>().hurt(1);
		}else if(tag == "sword"){
			hurt();
		} 
		/*Se o inimigo colidir com o o escudo, vai ser afastado. (tomar distancia)
		 */
		else if (tag == "shield"){
			takeAway();
		}
	}
	
	public void hurt(){
		Destroy(gameObject);
	}

	public void takeAway (){
		Vector3 velocity = transform.rigidbody.velocity;
		velocity *= -100;
		velocity = Vector3.Cross(velocity, new Vector3(0,-1,0));
		print(velocity);
		transform.rigidbody.AddForce(velocity, ForceMode.Impulse);
	}
}
